<?php
namespace app\admin\controller;
use think\Db;
use app\common\controller\order\Orderget;
class Renzhengcards extends Common
{
//   认证列表页面
    public function index()
    {
		return $this->fetch();	
    }
//	 认证表页面数据
    public function get_list()
    {	
		$page = input('page');
		$limit = input('limit');
		$sorch=input('sorch');
		$sorch_aaa=input('sorch_aaa');
		$Orderget=New Orderget();
		$where1=$Orderget->sorch($sorch,$sorch_aaa);
		if(empty($where1)){
			$where=[];
		}
		if(!empty($where1['TrueName'])){
			$where['a.Name']=$where1['TrueName'];
		}
		if(!empty($where1['IDCard'])){
			$where['a.IDCard']=$where1['IDCard'];
		}
	
		$data=Db::table('xb_renzen_cards a')
		->join('xb_mem_info b','a.UserID=b.ID','LEFT')
		->page($page,$limit)->order('a.ID desc')->where($where)
		->field('b.TrueName,b.TrueName2,a.Status,b.IDCard,a.RenzTime,a.ID')
		->select();
//		P($data);DIE;
        $cuont=Db::table('xb_renzen_cards a')
		->join('xb_mem_info b','a.UserID=b.ID','LEFT')
	    ->order('a.ID desc')
	    ->where($where)
		->field('b.TrueName,b.TrueName2,a.Status,b.IDCard,a.RenzTime,a.ID')
		->count('a.ID');
//		0待审核 1已认证 2认证失败
		foreach ($data as $k => $v) {
			if($v['Status']=='1'){
			$v['Status']='<span style="color:green;">已认证</span>';
			}
			if($v['Status']=='2'){
			$v['Status']='<span style="color:red;">认证失败</span>';
			}
            if($v['TrueName2']==$v['TrueName']){
			    $v['pipei']='<span style="color:green;">成功</span>';
			}else{
				$v['pipei']='<span style="color:red;">失败</span>';
			}
			$data[$k]=$v;
		}
		songsong($data,$cuont);	
    }
	//身份认证详情	
	public function detail(){
		$ID =input('get.ID');
		$renzen_cards = Db::table('xb_renzen_cards')->where('ID',$ID)->find();
		$meminfo=Db::table('xb_mem_info')->where(['ID'=>$renzen_cards['UserID']])->field('TrueName,IDCard,Sex')->find();
		$renzen_cards['TrueName']=$meminfo['TrueName'];
		$renzen_cards['IDCard']=$meminfo['IDCard'];
		$renzen_cards['Sex']=$meminfo['Sex'];
		if($renzen_cards['Sex']=='0'){
			$renzen_cards['Sex']='未知';
		}
		$this->assign('data',$renzen_cards);
		return $this->fetch();	
	}

	
		
//	身份证认证编辑页面
	public function editss(){
		$ID= input('ID');
		$data=Db::table('xb_renzen_cards')->where('ID',$ID)->find();
		$this->assign('data',$data);
		return $this->fetch();
		
	}
	//	身份证认证编辑操作
	public function edit(){
		$this->logs('身份证认证编辑');
		$data= input();
		if(!empty($data['Status']) && $data['Status']=='on'){
			$data['Status']='1';
			$dataxiuga['isID']='1';
		}else{
			$data['Status']='2';
			$dataxiuga['isID']='0';
		}
		$data['UpdateTime']=date('Y-m-d H:i:s');//时间
		$re=Db::table('xb_renzen_cards')->update($data);//修改身份证认证状态
		$UserID=Db::table('xb_renzen_cards')->where(['ID'=>$data['ID']])->value('UserID');//获取UserID
		$res=Db::table('xb_mem_info')->where(['ID'=>$UserID])->update($dataxiuga);//修改用户表身份证认证状态
		if($res){
	    show_success();
		}else{
			show_error();
		}	
	}
}
